
// A1 and A2.  Summary Statistics
// A1 and A2.  Summary Statistics
// A1 and A2.  Summary Statistics


// PRELIMINARIES

clear
set more off
set scheme s1mono


// LOAD DATA
	
use "JakielaOzierFernaldKnauer-preschool-data.dta", replace



// SUMMARY STATISTICS

** write the program

cap program drop summstat
program define summstat
confirm numeric var `1'
confirm e `2'

 display "Current variable:  `1'"

 quietly des `1'
 local l`1' : variable label `1'
 
 quietly sum `1', d
 local _mean = string(r(mean),"%03.2f")
 local _sd = string(r(sd),"%03.2f")
 local _median = string(r(p50),"%03.2f")
 if mod(r(p50),1)==0 {
 	local _median = r(p50)
 }
 local _min = string(r(min),"%03.2f")
 if mod(r(min),1)==0 {
 	local _min = r(min)
 }
 local _max = string(r(max),"%03.2f")
 if mod(r(max),1)==0 {
 	local _max = r(max)
 }
 local _N = r(N)
 
 file write `2' "`l`1'' & `_mean' & `_sd' & `_median' & `_min' & `_max' &`_N' \\  " _newline
 
end

** generate the tables

preserve

keep if roundage==3

cap file close fh
file open fh using "out/A1-summstats3yrs.tex", write replace
foreach var of varlist childage haz male cgmom momeduc momluo dadabsent_raw dadeduc_raw dadluo_raw ///
	hhsize sibs numassets schdist inschool {
	summstat `var' fh
}
file close fh

restore


cap file close fh
file open fh using "out/A2-summstatsALL.tex", write replace
foreach var of varlist childage haz male cgmom momeduc momluo dadabsent_raw dadeduc_raw dadluo_raw ///
	hhsize sibs numassets schdist inschool {
	summstat `var' fh
}
file close fh






